();};HelloWorld Hw;HelloWorld::HelloWorld(){......}HelloWorld::~HelloWorld(){......}int main(){return 0; }
To understand the structure details of global objects, it is necessary to study the Startup Process of the program further. In section 1 of this chapter, what does the init function pointer passed by _ start point? By tracking the address, init actually points to the _ libc_csu_init function. This function is located in the CSU/Elf-init.c of the glibc source code directory. Let's take
returns a string that is inserted where the current command is located.
The following is the built-in spec function: getenv getenv spec function with two parameters: an environment variable name and a string. If the environment variable is not defined, a critical error is generated. The return value is the value of the environment variable and the string is concatenated together. For example, if Topdir is defined as/path/to/top, then:
%:getenv (Topdir/include)
will be expanded i
destructor, and can achieve the same effect by defining ctors_section_asm_op and dtors_section_asm_op.
When a section can be named randomly, there are two variants that differ in the call of the crtstuff. C code. On systems that support. init section (run when the program starts), part of crtstuff. C is compiled into this section. The program is linked like this:
LD-O output_file crti. O crtbegin. O...-lgcc crtend. O crtn. o
The prologue (_ init) of
1. Analyze common helloworld programsFirst, write a simple helloworld program as follows:/* Hello. C */Int main (INT argc, char * argv []){Return 0}Compile the program:Gcc-O hello. cEquivalent compilation method:Gcc-C hello. cGcc-O hello. My-nostartfiles hello. O/usr/lib/crt1.o/usr/lib/crti. O/usr/lib/crtn. oIn redflag workstation 5.0, the GCC compiler 3.4.3 is compiled with 3589 bytes in size, and the diff command is used to compare the files with th
definitionOBJ/FK.O: In the function ' _start ':(. text+0x0): ' _start ' is defined multiple times/usr/lib/gcc/x86_64-linux-gnu/4.8/.. /.. /.. /x86_64-linux-gnu/crt1.o:/build/eglibc-mjixcm/eglibc-2.19/csu/.. /sysdeps/x86_64/start. s:118: For the first time in this definitionOBJ/FK.O: In the function ' _init ':(. init+0x0): ' _init ' is defined multiple times/usr/lib/gcc/x86_64-linux-gnu/4.8/.. /.. /.. /x86_64-linux-gnu/crti.o:/build/eglibc-mjixcm/eglibc-2.19/csu/.. /sysdeps/x86_64/
-O/tmp/ccc02j4q. O/tmp/ccte4jk2. sGNU Debugger er version 2.20.1 (i486-linux-gnu) using BFD version (GNU binutils for Ubuntu) 2.20.1-system.20100303Compiler_path =/usr/lib/GCC/i486-linux-gnu/4.4.3/:/usr/lib/GCC/i486-linux-gnu/4.4.3/:/usr/lib/GCC/i486-linux-gnu /: /usr/lib/GCC/i486-linux-gnu/4.4.3/:/usr/lib/GCC/i486-linux-gnu/:/usr/lib/GCC/i486-linux-gnu/4.4.3 /: /usr/lib/GCC/i486-linux-gnu/LIBRARY_PATH =/usr/lib/GCC/i486-linux-gnu/4.4.3/:/usr/lib/GCC/i486-linux-gnu/4.4.3/:/usr/lib/GCC/i486-linux
I mentioned a cool Dongdong last year (see here), but my phone is its enhanced version, although I applied for an invitation code for beta of my phone very early (some beta code is attached at the end of this Article), I can try it today. First, open the browser to the http://myphone.microsoft.com, click sign in, and then apply to use my phone or directly enter the invitation code to start using immediately, here I will directly enter the beta code in.
Then open the phone browser, in the addres
UseGccCompileCodeWe all know that there will be a compilation link process, andLDIt is the connector used for linking.
1 Source File hello. c# Include lt; stdio. H gt;
Int main (INT argc, char * argv []){Printf ( quot; Hello \ n quot ;);Return 0;}
2 GCC CompilationGCC hello. C-O helloThen run./HelloOutput result hello
3 GCC compilation,LDConnectionGcc-C hello. C-O hello. oLD-O hello. oThe generated Hello file cannot be executed.
4. SolutionSince the hello generated in step 2 can be
with the compilation process, the compilation process is relatively simple. You can translate the compilation commands one by one based on the comparison table of the Assembly commands and machine commands.
$ Gcc-c hello. c-o hello. o
Or
$ As hello. s-o hello. co
Because the content of hello. o is a machine code, it cannot be viewed in the form of common text (if you open the vi, you will see garbled code ).
4. Link (Linking)
Call the linker ld to link a large number of target files required f
: File or directory not found
4. ld can't find crti. o
The solution is as follows:
1. apt-get install libgmp10-dev libmp fr-dev libmp C-dev
2. apt-get install flex bison
3. 4. Compile the script on the Internet and run it directly.
The following is the script compilation process:
1. Install gmp according to steps 1 and 2 above, and so on;
2. Download the code on the official website in $ HOME/src/gcc-4.7/files/
3. Download the script in the attachment
created by the operating system.The assembler generates the first type of target file. For the last two methods, some other processing is required. This is the work of The Link program.5. Link Program (Linking)The target file generated by the assembler cannot be executed immediately. There may be many unsolved problems. For example, a function in a source file may reference a symbol (such as a variable or function call) defined in another source file, or call a function in a library file in a p
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.